package cn.wolfcode.luowowo.website.util;

import cn.wolfcode.luowowo.common.exception.LogicException;
import cn.wolfcode.luowowo.common.util.AJaxResult;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;

@ControllerAdvice
public class CommonExcetionHandler {

    @ExceptionHandler(LogicException.class)
    @ResponseBody
    public AJaxResult LogicExceptionHandler(Exception e, HttpServletResponse resp){
        AJaxResult aJaxResult = new AJaxResult();
        aJaxResult.mark(e.getMessage());
        return aJaxResult;
    }

    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public AJaxResult RuntimeExceptionHandler(Exception e, HttpServletResponse resp){
        AJaxResult aJaxResult = new AJaxResult();
        aJaxResult.mark("系统繁忙中, 请稍后重试");
        e.printStackTrace();
        return aJaxResult;
    }
}
